package cn.schoolwow.quickdao.module.operation.flow.generateEntity.single;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;

public class WriteClassToFileFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        File targetFile = (File) flowContext.checkData("targetFile");
        StringBuilder builder = (StringBuilder) flowContext.checkData("builder");

        Files.write(targetFile.toPath(), builder.toString().getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE,StandardOpenOption.WRITE);
    }

    @Override
    public String name() {
        return "写入类信息到文件中";
    }
}
